<template>
  <div>
    <!-- @open="handleOpen"
          @close="handleClose" -->
    <el-container>
      <el-aside width="200px">
        <el-menu
          unique-opened
          :default-active="$route.path"
          class="el-menu-vertical-demo"
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b"
          router
        >
        <el-menu-item index="/">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>首页</span>
            </template>
          </el-menu-item>

            <div v-for="item in userInfo.menus" :key="item.id">
               <!-- 目录 -->
            <el-submenu :index="item.id + ''" v-if="item.children">
              <template slot="title">
                <i :class="item.icon"></i>
                <span>{{ item.title }}</span>
              </template>
              <el-menu-item-group>
                <el-menu-item
                  :index="i.url"
                  v-for="i in item.children"
                  :key="i.id"
                  >{{ i.title }}</el-menu-item
                >
              </el-menu-item-group>
            </el-submenu>
            <!-- 菜单 -->
            <el-menu-item :index="item.url" v-else>
              <i class="el-icon-s-order"></i>
              <span slot="title">{{ item.title }}</span>
            </el-menu-item>
            </div>
          <!-- <el-submenu :index="item.id + ''" v-for="(item) in userInfo.menus " :key="item.id" >
            <template slot="title">
              <i :class="item.icon"></i>
              <span>{{item.title}}</span>
            </template>
            <el-menu-item-group>
              <el-menu-item :index="i.url" v-for="i in item.children" :key="i.id">{{i.title}}</el-menu-item>
              <el-menu-item index="/role">角色管理</el-menu-item>
              <el-menu-item index="/manage">管理员管理</el-menu-item>
            </el-menu-item-group>
          </el-submenu> -->

          <!-- <el-submenu index="3">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>商城管理</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="/cate">商品分类</el-menu-item>
              <el-menu-item index="/specs">商品规格</el-menu-item>
              <el-menu-item index="/goods">商品管理</el-menu-item>
              <el-menu-item index="/member">会员管理</el-menu-item>
              <el-menu-item index="/banner">会轮播图管理</el-menu-item>
              <el-menu-item index="/seckill">秒杀活动管理</el-menu-item>
            </el-menu-item-group>
          </el-submenu> -->
        </el-menu>
      </el-aside>
      <el-container>
        
        <el-header>
          <span>{{userInfo.username}}</span>
          <el-button type="primary" @click="logout">退出登录</el-button>
        </el-header>
        <el-main>
            <el-breadcrumb v-if="$route.meta.title" separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>{{$route.meta.title}}</el-breadcrumb-item>
          </el-breadcrumb>
          <!-- 二级路由视图 -->
          <router-view class="second-con"></router-view>    
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { mapActions,mapGetters } from 'vuex';
export default {
  computed:{
    ...mapGetters({
      userInfo:'userInfo',//用户信息

    })
  },
  mounted() {},
  methods: {
    ...mapActions({
      changeUserInfo: "changeUserInfo",
    }),
    //退出登录
    logout(){
      this.changeUserInfo({});
      this.$router.replace('/login');
    }
  },
};
</script>

<style scoped>
.el-aside,
.el-menu {
  height: 100vh;
}
.el-header {
  background-color: rgb(83, 107, 138);
}
</style>